#ifndef YCCONTROLSTASKPROGRESSDIALOG_H
#define YCCONTROLSTASKPROGRESSDIALOG_H
#include "base/task/task.h"
#include <functional>
#include <QDialog>
#include <QPointer>

QT_BEGIN_NAMESPACE
class QTimer;
class QProgressBar;
class QPushButton;
class QFrame;
class QLabel;
QT_END_NAMESPACE

namespace yc {

class TaskProgressDialog : public QDialog
{
    Q_OBJECT

public:
    using LeftMessage = std::function<QString()>;

    TaskProgressDialog(yc::Task& task, const QString& title, QWidget* parent = nullptr);
    TaskProgressDialog(yc::Task& task, const QString& title, const LeftMessage& left_message,
                       QWidget* parent = nullptr);
    ~TaskProgressDialog() override;

    int start();

protected:
    void keyPressEvent(QKeyEvent* ke) override;
    void closeEvent(QCloseEvent* ce) override;

private:
    QString leftMessage() const;
    void onTimeout();
    void onFinished();
    void onFailed(int error, const QString& message);

    QPointer<yc::Task> task_;
    LeftMessage left_message_;
    QLabel* status_label_;
    QLabel* left_label_;
    QProgressBar* progress_bar_;
    QTimer* timer_;
};

} // namespace yc

#endif // YCCONTROLSTASKPROGRESSDIALOG_H
